<template>
	<view class="content">
		<view class="buying-wrap">
			<view class="buying-tab">
				<view :class="type == 1? 'buy':'sell'" @click="changeTab(1)">我要买入</view>
				<view :class="type == 2 ?'buy':'sell'" @click="changeTab(2)">我要卖出</view>
			</view>
			<!-- 			<view class="paychecktype" v-show="type == 2">
				<view class="title">
					<text class="circle"></text>
					<view>付款方式</view>
				</view>
				<view class="changetype">
					<radio-group @change="radioChange">
						<view class="typeBox">
							<view class="wx">
								<radio :value="1+''" color="#ee5b25" :checked="paychecktype == 1" />微信
							</view>
							<view class="alipay">
								<radio :value="2+''" color="#ee5b25" :checked="paychecktype == 2" />支付宝
							</view>
						</view>
					</radio-group>
				</view>
			</view> -->
		</view>
		<view class="deallist">
			<view class="info">
				<view class="title">
					<view>快速交易</view>
					<!-- <view>交易记录</view> -->
				</view>
				<view class="cell" v-for="(item,index) in deallobbylist" :key="index"  @scrolltolower="initdata">
					<view class="cell-l">
						<image class="bgimage" src="../../static/emptyCart.jpg" mode=""></image>
					</view>
					<view class="cell-r">
						<view class="user">
							<view class="name">{{item.order_id}}</view>
							<!-- <view class="isvip">黄金会员</view> -->
							<view class="pay-type" v-if="item.money_type == 2">
								<image src="../../static/zfb.png" class="wxpay" mode=""></image>
								支付宝
							</view>
							<view class="pay-type" v-if="item.money_type == 1">
								<image src="../../static/wx.png" class="wxpay" mode=""></image>
								微信支付
							</view>
						</view>
						<view class="goodsinfo">
							<view class="num">数量：{{item.cbt}}</view>
							<view class="price">单价：￥{{item.danjia}}</view>
						</view>
						<view class="allcount">
							<view class="totalprice">总价：￥{{item.qian}}</view>
							<view class="buy" v-show="type == 1" @click="buy(item.id,type,item.money_type)">一键买入</view>
						</view>
					</view>
				</view>
				
				
				<uni-load-more v-if="needLoad" :status="loadingType"></uni-load-more>
			</view>
		</view>
		<view class="publish" @click="publish">
			我要发布
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadingType: 'more',
				page: 1,
				needLoad: true,
				loading: false,
				isdone: false,
				paychecktype: 1,
				type: 0,
				deallobbylist: [],
				providerList: [],
				id:''
			}
		},
		onLoad(options) {
			this.type = options.type
			// if (this.type == 1) {
			// 	console.log('1')
			// 	this.deallist()
			// } else {
			// 	console.log('2')
			// 	this.deallist()
			// }
		},
		onShow(){
			this.deallobbylist = [];
			this.deallist()
		},
		methods: {
			tobuying(item){
				let that = this;
				var list = JSON.stringify(item)
				uni.navigateTo({
					url:'/subPackage/paynow/paynow?item='+list
				})
			},
			changeTab(status) {
				this.type = status
				this.page = 1;
				this.deallobbylist = [];
				if (this.type == 1) {
					// this.deallobbylist = [];
					this.deallist()
				} else {
					// this.deallobbylist = [];
					this.deallist()
				}
				
			},
			onReachBottom() {
				let that = this;
				if (that.isdone) {
					return false;
				}
				that.loading = true;
				that.page++
				that.loadingType = 'loading'
				that.deallist()
			},
			radioChange() {
				
			},
			buy(id, type, money_type) {
				let that = this;
				uni.request({
					url: 'https://www.ggshop1688.com/api/transaction/get_payinfo',
					data: {
						pay_type: this.paychecktype,
					},
					method: 'POST',
					header: {
						token: uni.getStorageSync('userInfo').token
					},
				}).then(res => {
					if (res[1].data.status == 1) {
						if(res[1].data.data.length == 0){
							that.$api.msg('还没有添加收款码请先添加');
							setTimeout(() => {
								uni.navigateTo({
									url: '../uploadimg/uploadimg?id=' + that.id
								})
							}, 500)
						}else{
							this.paynow(id,type,money_type)
						}
					}else{
						
					}
					if (res[1].data.status == -1) {
						if (data[1].data.msg == '还没有添加微信收款码请先添加' || data[1].data.msg == '还没有添加支付宝收款码请先添加') {
							that.$api.msg(res[1].data.msg)
							setTimeout(() => {
								uni.navigateTo({
									url: '../uploadimg/uploadimg?id=' + that.id
								})
							}, 500)
						}
					}
				})
			},
			paynow(id,type,money_type){
				const paycode = new Promise((resolve, reject) => {
					uni.request({
						url: 'https://www.ggshop1688.com/api/transaction/buy',
						data: {
							id: id,
							type: type,
							money_type: money_type
						},
						method: 'POST',
						header: {
							token: uni.getStorageSync('userInfo').token
						},
					}).then(data => {
						if (data[1].data.status == 1) {
							resolve(data[1].data.data)
						}else{
							this.$api.msg(data[1].data.msg)
						}
					})
				})
				paycode.then(result => {
					console.log(result)
					var url = result.payurl
					var payParam = JSON.stringify(result.payinfo)
					uni.navigateTo({
						url:'/subPackage/paynow/paynow?id='+id + '&payParam='+payParam
					})
				}).then(data => {
					console.log(data)
				
				})
			},
			deallist() {
				let that = this;
				uni.request({
					url: 'https://www.ggshop1688.com/api/transaction/out_in_list',
					data: {
						type: this.type == 1 ? '' : this.type,
						self: this.type == 1 ? false : true,
						p:this.page,
						status:0
					},
					method: 'POST',
					header: {
						token: uni.getStorageSync('userInfo').token
					},
				}).then(data => {
					if(data[1].data.status == 1){
						data[1].data.data.list.forEach(item => {
							this.deallobbylist.push(item)
						})
						that.loadingType = 'more'
						if (data[1].data.data.list.length < 20) {
							that.loading = true;
							that.isdone = true;
							that.loadingType = 'noMore'
						}
					}else{
						that.$api.msg('error_message'+res[1].data.msg)
					}
				}).catch(err=>{
					
				})
			},
			publish() {
				uni.navigateTo({
					url: '../selecetpublish/selecetpublish'
				})
			}
		}
	}
</script>
<style>

</style>
<style lang="scss" scoped>
	.content {
		font-size: 24upx;
		background-color: #fff;
		height: 100vh;
		padding: 20upx;

		.buying-wrap {
			.buying-tab {
				display: flex;
				justify-content: space-around;
				padding: 20upx 0px;

				.buy {
					height: 80upx;
					line-height: 80upx;
					background-color: #ff6600;
					text-align: center;
					color: #fff;
					width: 45%;
					border-radius: 5px;
				}

				.sell {
					height: 80upx;
					line-height: 80upx;
					background-color: #ccc;
					text-align: center;
					color: #fff;
					width: 45%;
					border-radius: 5px;
				}
			}

			.paychecktype {
				border: 1px solid #f2f2f2;
				background-color: #f2f2f2;
				padding: 20upx;

				.title {
					padding: 20upx 0px;
					display: flex;
					align-items: center;

					.circle {
						width: 14upx;
						height: 14upx;
						background-color: #f90202ab;
						display: inline-block;
						border-radius: 50%;
						margin-right: 10upx;
					}
				}

				.changetype {
					.typeBox {
						display: flex;
						align-items: center;

						.wx {
							display: flex;
							align-items: center;
							margin-right: 30upx;

							.uni-radio-wrapper {
								.uni-radio-input {
									width: 15px;
									height: 15px;
									box-sizing: border-box;
								}
							}
						}

						.alipay {
							display: flex;
							align-items: center;

							.uni-radio-input {

								width: 15px;
								height: 15px;
								box-sizing: border-box;
							}
						}
					}
				}
			}
		}

		.deallist {
			padding-bottom: 75px;

			.info {
				.title {
					display: flex;
					justify-content: space-between;
					padding: 20upx 30upx;
				}

				.cell {
					display: flex;
					background-color: #f2f2f2;
					padding: 20upx;
					margin-bottom: 10px;
					border-radius: 10px;

					.cell-l {
						width: 160upx;
						height: 160upx;
						margin-right: 20upx;

						.bgimage {
							width: 100%;
							height: 100%;

							img {
								width: 100%;
								height: 100%;
							}
						}
					}

					.cell-r {
						display: flex;
						flex-direction: column;
						justify-content: space-between;
						width: 70%;

						.user {
							display: flex;
							align-items: center;

							.isvip {
								font-size: 16upx;
								height: 30upx;
								line-height: 30upx;
								background-color: #fce6d7;
								color: #fff;
								text-align: center;
								border-radius: 10upx;
								width: 120upx;
								margin-left: 30upx;
							}

							.pay-type {
								margin-left: 30upx;
								display: flex;
								align-items: center;

								.wxpay {
									width: 30upx;
									height: 30upx;
									margin-right: 10upx;

									img {
										width: 100%;
										height: 100%;
									}
								}
							}
						}

						.goodsinfo {
							display: flex;
							align-items: center;

							.num {}

							.price {
								margin-left: 30upx;
							}
						}

						.allcount {
							display: flex;
							align-items: center;
							justify-content: space-between;
							height: 40upx;

							.totalprice {}

							.buy {
								background-color: #ee5b25;
								width: 160upx;
								height: 50upx;
								line-height: 50upx;
								text-align: center;
								color: #fff;
								border-radius: 6px;

							}
						}
					}
				}
			}
		}

		.publish {
			background-color: #ff6600;
			color: #fff;
			height: 70upx;
			line-height: 70upx;
			text-align: center;
			width: 95%;
			border-radius: 5px;
			position: fixed;
			bottom: 30px;
		}
	}
</style>
